<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Customer;
use App\User;

class CustomerApiController extends Controller
{
    public function index(Request $request){
        $data=$request->all();
        if(!empty($data['uuid'])){
            $uuid=$data['uuid'];
            $user=User::where('uuid',$uuid)->first();
            if(!empty($user)){
                return view('addcustomer')->with('user',$user);
            }
            else
            {
                print('您的二维码已经失效，请联系管理员13635456575');
            }
        }
        else{
            print('您的二维码已经失效，请联系管理员13635456575');
        }

    }
    public function addCustomer(Request $request){
        $url='https://creditcard.cmbc.com.cn/wsv2/smp_web/mgm/recomAccept.html?rKey=b2774f236dc266c6284bcaed7dd00c6562d971e8eb55c8a38af1f03cc9d7e078c5e925952f50c3b22ce1fa418134679c&rpKey=a9a5f65c4177beca4502ed9f492ebaff3155e1b99fa7ae14e9f5a5882ce98fd4c6dec5f07ca833a4ed93cd083b610d92bf5df8e22ce6e392d1051c6eb13b7f88&ct=1542254519070';
        $data=$request->all();
        $customer=new Customer();
        $customer->name=$data['name'];
        $customer->phone=$data['phone'];
        $customer->idcard=$data['idcard'];
        $customer->userid=$data['userid'];
        $customer->username=$data['username'];
        if(empty(Customer::where('idcard',$customer->idcard)->first())){
            $customer->save(); 
        }
        return redirect($url);
    }

}
